<!DOCTYPE html>
<html>
<head>
<title>clinicDetail.html</title>

<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/Hospital/lib/layui-v2.1.6/layui/css/layui.css" media="all">
<style type="text/css">
select {
	height: 38px;
	line-height: 1.3;
	line-height: 38px\9;
	border-width: 1px;
	border-style: solid;
	background-color: #fff;
	border-radius: 2px;
	width: 100%;
}
.iCss {
	color: red;
	padding-right: 5px;
}
.row {
	margin-top: 10px;
}
</style>
</head>
<body>
	<div class="layui-container" style="">
		<div class="layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1">
				<span class="layui-form-label"><i class="iCss">*</i>门诊名称: </span>
			</div>
			<div class="layui-col-xs5">
				<input id="clinicName" class="layui-input" type="text">
			</div>
		</div>
		<div class="layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1">
				<span class="layui-form-label">门诊负责人: </span>
			</div>
			<div class="layui-col-xs5 ">
				<select id="principal" name="principal" class="layui-input-inline">
				</select>
			</div>
		</div>
		<div class="layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1">
				<span class="layui-form-label">联系电话: </span>
			</div>
			<div class="layui-col-xs5">
				<input id="phone" class="layui-input" type="text">
			</div>
		</div>
		<div id="div_createTime" class="layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1">
				<span class="layui-form-label">创建时间: </span>
			</div>
			<div class="layui-col-xs5">
				<input id="createTime" class="layui-input" type="text" disabled>
			</div>
		</div>
		<div class="layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1">
				<span class="layui-form-label">地址: </span>
			</div>
			<div class="layui-col-xs7">
				<textarea id="address" class="layui-textarea" type="text"></textarea>
			</div>
		</div>
	</div>
</body>
<script src="/Hospital/lib/jquery.min.js" charset="utf-8"></script>
<script src="/Hospital/lib/layui-v2.1.6/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
	$(function() {
		initFrame();//初始化表单数据
	});
	
	//初始化表单数据
	function initFrame() {
		var operator = localStorage.getItem("clinicTable_operator");
		if(operator == 1) {
			//如果是新建门诊
			initAddFrame();
		}
		if(operator == 2) {
			//如果是修改门诊
			initAlterFrame();
		}
	}
	
	function initAddFrame() {
		$("#div_createTime").css({"display":"none"});
		$.ajax({
			type : "post",
			url : "/Hospital/userController/getClinicPrincipal",
			data : "",
			success : function(response) {
				var result = response.result;
				for (var i = 0; i < result.length; i++) {
					var employeeId = result[i].employeeId;
					var employeeCode = result[i].employeeCode;
					var name = result[i].name;
					$("#principal").append("<option value="+employeeId+" _code="+employeeCode+">" + name + "</option>");
				}
			},
		});
	}
	
	function initAlterFrame() {
		var clinicData = JSON.parse(localStorage.getItem("clinicDetail"));
		var permission = JSON.parse(localStorage.getItem("loginUser")).permission;
		$("#clinicName").val(clinicData.clinicName);
		$("#address").val(clinicData.address);
		$("#phone").val(clinicData.phone);
		$("#createTime").val(clinicData.createTime);

		if (permission.alterClinic == 5) {
			//管理员
			$.ajax({
				type : "post",
				url : "/Hospital/userController/getClinicPrincipal",
				data : "",
				success : function(response) {
					var result = response.result;
					for (var i = 0; i < result.length; i++) {
						var employeeId = result[i].employeeId;
						var employeeCode = result[i].employeeCode;
						var name = result[i].name;
						$("#principal").append("<option value="+employeeId+" _code="+employeeCode+">" + name + "</option>");
					}
					$("#principal").val(clinicData.principalId);
				},
			});
		} else if (permission.alterClinic >= 3) {
			//门诊负责人
			$("#principal").attr("disabled", true);
			$("#principal").append(
					"<option value="+clinicData.principalId+" _code="+clinicData.principalCode+">" + clinicData.principalName
							+ "</option>");
		}
	}
	
	function getParam() {
		var param = {};
		var operator = localStorage.getItem("clinicTable_operator");
		if(operator == 1) {
			//如果是新建门诊
			param = {
				name : $("#clinicName").val(),
				address : $("#address").val(),
				phone : $("#phone").val(),
				employeeId : $("#principal").val(),
			};	
		}
		if(operator == 2) {
			//如果是修改门诊
			var clinicData = JSON.parse(localStorage.getItem("clinicDetail"));
			param = {
				clinicId : clinicData.clinicId,
				name : $("#clinicName").val(),
				address : $("#address").val(),
				phone : $("#phone").val(),
				employeeId : $("#principal").val(),
			};	
		}
		return param;
	}
</script>
</html>
